#include "BoomEntity.h"
#include "EffectManager.h"



void BoomEntity::_fire(double x, double y)
{
	isFired = true;
	_isInteract = false;
}

void BoomEntity::_recreate()
{
	_time = 0;
	_count = 0;
	_data->canInteract = true;
	_isInteract = false;
}

BoomEntity::BoomEntity(int id, int type, double x, double y)
{
	_data = new BoomData(id, type, x, y);
	isFired = false;
	_isInteract = false;
	_data->canInteract = true;
	_count = 0;
	_time = 0;
	_x0 = x;
	_y0 = y;
}

void BoomEntity::update(long time)
{
	_time++;

	//double currenty = _data->getRect()->Y;
	//if(_isInteract)
	//{
	//	if(!isFired)
	//	{
	//		//_fire(_data->getRect()->X, currenty);
	//	}

	//	if(isFired)
	//	{
	//		_count++;
	//		if(_count >= TIME)
	//		{
	//			_count = 0;
	//			isFired = false;
	//			_recreate();
	//		}
	//	}

	//	return;

	//}
	if (_count > 0) {
		_count--;
		if (_count ==  0) {
			_recreate();
		}
	} else 	if(_time % 5 == 0)
	{
		_data->getRect()->Vy = (Vo*_time + (GRAVITY * _time * _time)/2)/800 + 5;
		_data->getRect()->Vx = Vo*_time/80;

		_data->getRect()->X += _data->getRect()->Vx;
		_data->getRect()->Y += _data->getRect()->Vy;
		_data->sprites->updateCurrent();
	}

	/*if(!isFired)
	{
	_data->sprites->updateCurrent();
	}*/
}

void BoomEntity::draw(long time)
{
	if(_data->canInteract)
	{
		_data->sprites->draw();
	}
}

AbstractData* BoomEntity::getAbstractData()
{
	return _data;
}

void BoomEntity::updateData(int actions, int effect)
{
	if(actions == ACTIONS_BOOM_KILL)
	{
		_isInteract = true;
		EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Object_Burning,_data->getRect()->X, _data->getRect()->Y);
		_data->canInteract = false;
		_data->getRect()->X = _x0;
		_data->getRect()->Y = _y0 + 100;
		isFired = true;
		_count = TIME;
		//_isInteract = false;

	}
}

BoomEntity::~BoomEntity()
{

}
